import axios from 'axios';
let instance = axios.create({
    baseURL: '/api',
    timeout: 5000,
});
instance.interceptors.request.use(
    config => {
        // console.log('请求之前拦截');
        if (config.url == '/sendSMS') {
            config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        }
        let mytoken = localStorage.getItem('x-auth-token');
        if (mytoken) {
            config.headers['x-auth-token'] = mytoken;
        }
        return config;
    },
    err => {
        return Promise.reject(err);
    }
);

instance.interceptors.response.use(
    res => {
        // console.log('响应之前拦截');
        if (res.data.code != 0 && res.data.code != 400 && res.data.code != 407) {
            // alert(res.data.message);
            return false;
        }
        return res.data;
    },
    err => {
        return Promise.reject(err);
    }
);
export default instance;
